//
//  VIPAllCollectionViewController.swift
//  GhostWorld
//
//  Created by Kam on 2018/5/17.
//  Copyright © 2018 LKGood. All rights reserved.
//

import UIKit

class VIPAllViewController: VIPChildViewController {
  
  // MARK: - IBOutlets
  
  @IBOutlet weak var collectionView: VIPAllCollectionView!
  
  // MARK: - Lifecycle
  
  override func viewDidLoad() {
    super.viewDidLoad()
    
    collectionView.loadData(rootGroupIdentifier: 0)
  }
  
  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
  }
  
  // MARK: - IBActions
  
  
  
  // MARK: - Public methods
  
  override func prepareUI() {
    collectionView.backgroundColor = .clear
    collectionView.selectionDelegate = self
    collectionView.scrollDelegate = self
  }
  
  override func getScrollView() -> UIScrollView {
    return collectionView
  }
}

// MARK: - VIPAllCollectionViewSelectionDelegate

extension VIPAllViewController: VIPAllCollectionViewSelectionDelegate {
  
  func collectionView(_ collectionView: VIPAllCollectionView, didSelectItem item: VIPAllResultItem) {
    if item.type == .album {
      let storyboard = UIStoryboard(name: "ContentBrowsing", bundle: nil)
      let albumDetailViewController = storyboard.instantiateViewController(withIdentifier: "AlbumDetailViewController") as! AlbumDetailViewController
      albumDetailViewController.albumIdentifier = Int(item.identifier)
      navigationController?.pushViewController(albumDetailViewController, animated: true)
    } else {
      let storyboard = UIStoryboard(name: "VIP", bundle: nil)
      let vipAllGroupViewController = storyboard.instantiateViewController(withIdentifier: "VIPAllGroupViewController") as! VIPAllGroupViewController
      vipAllGroupViewController.rootGroupIdentifier = item.identifier
      vipAllGroupViewController.groupName = item.name
      navigationController?.pushViewController(vipAllGroupViewController, animated: true)
    }
  }
}

// MARK: - UIScrollViewDelegate

extension VIPAllViewController: VIPAllCollectionViewScrollDelegate {
  func vipAllCollectionViewDidScroll(_ scrollView: UIScrollView, didScroll: CGFloat) {
    scrollViewDelegate?.vipChildViewController(self, didScroll: didScroll)
  }
}
